{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# What's this notebook for?\n",
    "\n",
    "If you care about the compile time for your model, you should minimize the number of cvxpy Constraint and Variable objects necessary to specify your model. For example, if you needed to write the constraint \"Ax = b\", it is grealy preferred that you do this by \"A * x == b\", rather than \"a_i * x == b_i\" for every row a_i of A and every entry b_i of b.\n",
    "\n",
    "This notebook provides explicit demonstrations of how you can expect compile time for cvxpy to vary based on how you specify your model."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Introduction\n",
    "\n",
    "Throughout this notebook, we will consider the problem\n",
    "\n",
    "P(A,b,c) = min{ c.T * x  :  A x = b, 0 <= x <= 1}\n",
    "\n",
    "where A is an m-by-n matrix. Note that this is really the best-case scenario for cvxpy compile times: linear equality and inequality constraints require very few transformations before being handed to a low level solver. If you use more complex constraints (such as norm(x) <= d.T * x, or semidefinite constraints), you can expect the trends demonstrated in this notebook to become even more pronounced.\n",
    "\n",
    "At a high level, our tests are as follows: \n",
    "\tgenerate random problem data A, b, c of the appropriate sizes.\n",
    "\tconstruct a cvxpy Problem object \"prob\" representing P(A,b,c).\n",
    "\trecord the amount of time it takes for prob.solve(max_iters=1) to execute.\n",
    "\n",
    "Since we're only timing prob.solve(max_iters=1), it's clear that if *this* step runs too slow, the only option available to the user is to change how the problem is represented.\n",
    "\n",
    "The following code cell defines the helper functions we'll use in our tests."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cvxpy\n",
    "import scipy\n",
    "import time\n",
    "import numpy as np\n",
    "from matplotlib import pyplot as plt\n",
    "\n",
    "\n",
    "def compile_time(prob, solver='ECOS'):\n",
    "    # Return the amount of time needed to call prob.solve(max_iters=1).\n",
    "    #\n",
    "    # Because we aren't giving the solver enough iterations to actually solve the problem,\n",
    "    # cvxpy will throw an error saying that the solver \"failed.\" We don't actually\n",
    "    # care that the solver only had one iteration to work with, we only care that the \n",
    "    # solver read the problem data.\n",
    "    start = time.time()\n",
    "    try:\n",
    "        prob.solve(solver=solver, max_iters=1)\n",
    "        end = time.time()\n",
    "    except cvxpy.SolverError:\n",
    "        end = time.time()\n",
    "    return end-start\n",
    "\n",
    "\n",
    "def gen_A_b_c(m, n):\n",
    "    # Generate data for a linear program which is guaranteed to be feasible.\n",
    "    A = scipy.sparse.rand(m, n, density=0.1).toarray()\n",
    "    x0 = np.random.rand(n, 1)\n",
    "    b = np.dot(A, x0)\n",
    "    c = np.random.randn(n, 1)\n",
    "    return A, b, c\n",
    "\n",
    "\n",
    "def scalarized_problem(A, b, c):\n",
    "    # Generate a cvxpy Problem object of the planned form, where \n",
    "    #   (1) upper and lower bounds are specified on each element of x individually, and\n",
    "    #   (2) equality constraints A x = b are specified one row at a time.\n",
    "    x = cvxpy.Variable(shape=(A.shape[1], 1))\n",
    "    constraints = list()\n",
    "    for i in range(x.size):\n",
    "        constraints.append(x[i] >= 0)\n",
    "        constraints.append(x[i] <= 1)\n",
    "    for i in range(A.shape[0]):\n",
    "        constraints.append(A[i, :] * x == b[i])\n",
    "    objective = cvxpy.Minimize(c.T * x)\n",
    "    prob = cvxpy.Problem(objective, constraints)\n",
    "    return prob\n",
    "\n",
    "\n",
    "def vectorized_problem(A, b, c):\n",
    "    # Generate a cvxpy Problem object of the planned form, where \n",
    "    #   (1) upper and lower bounds are specified on the entire vector \"x\" at once, and\n",
    "    #   (2) equality constraints A x = b are specified by a single cvxpy Constraint object.\n",
    "    x = cvxpy.Variable(shape=(A.shape[1], 1))\n",
    "    constraints = [0 <= x, x <= 1, A * x == b]\n",
    "    objective = cvxpy.Minimize(c.T * x)\n",
    "    prob = cvxpy.Problem(objective, constraints)\n",
    "    return prob"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Test 1: Fix n and vary m.\n",
    "\n",
    "For our first set of tests, we'll fix n and vary m. This will allow us to see how cvxpy compile times vary when we linearly increase the size of the problems we're facing. It shouldn't take much more than 1 minute for the following cell to run."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x7f17bfdca910>"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAW4AAAD8CAYAAABXe05zAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAIABJREFUeJzt3X2cjXX+x/HXF1PIbUytclsbG3LXpCgkRWG1SkKisoukjZZk29z0604iidJUUtjcpVZC0q60Sm7KTZvkJmkaZYww7ufm+/vjezBpmDOcc65znfN+Ph7nMTPXXHPm45rjPdd8r+/1/RhrLSIi4h+FvC5AREQKRsEtIuIzCm4REZ9RcIuI+IyCW0TEZxTcIiI+o+AWEfEZBbeIiM8ouEVEfKZIOJ60fPnytmrVquF4ahGRmLRq1aqd1trEYPYNS3BXrVqVlStXhuOpRURikjHm+2D31VCJiIjPKLhFRHxGwS0i4jNhGePOS2ZmJikpKRw6dChS3zJuFC1alIoVK5KQkOB1KSISAREL7pSUFEqWLEnVqlUxxkTq28Y8ay3p6emkpKRQrVo1r8sRkQiI2FDJoUOHKFeunEI7xIwxlCtXTn/JiMSRiI5xK7TDQ8dVJL7kG9zGmBrGmNW5HnuNMf0iUZyIiC9YC/Pnw4gREfl2+Qa3tXaDtbaetbYecDlwAHgn7JVFma1bt1K7du0Cf13jxo3P+HtPmjSJvn37nvHziEiIHTkCb7wBdepA69YwYQJEYNiyoEMlLYDN1tqg7/CJV9nZ2QB8+umnHlciIiG3Zw888wxUqwZ33QXGuADfsAGKFg37ty9ocHcC3gpHIeG2f/9+2rRpQ926dalduzbTp09nxYoVNG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LMwuvXbaivwp7qAVyD+/NgLbA68GgNTAbWBbbPASrk+ppHcL9lNxCmK/KnqPci3JX1NcD/gEcC28sBHwEbA2/PDWw3wPhAveuApAjXWxxIB0rn2hY1xxb3C2U7kIk7A+lxOscSN768KfC4O4K1bsKNUx597U4I7Htr4PWxBvgC+GOu50nCBeZmYByBm94iVG+Bf/aB/4/fBj73SKRqDWyfBPQ+YV9Pjy0nzyxPX7e6c1JExGd056SIiM8ouEVEfEbBLSLiMwpuERGfUXCLiPiMgltExGcU3CIiPqPgFhHxmf8H+qn8KwDZxeEAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f17d751f8d0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ms1 = [250, 500, 1000, 1500, 2000]\n",
    "n = 250\n",
    "ts1 = list()\n",
    "tv1 = list()\n",
    "for m in ms1:\n",
    "    A, b, c = gen_A_b_c(m, n)\n",
    "    p = vectorized_problem(A, b, c)\n",
    "    tv1.append(compile_time(p))\n",
    "    p = scalarized_problem(A, b, c)\n",
    "    ts1.append(compile_time(p))\n",
    "\n",
    "plt.plot(ms1, ts1, 'r', label='scalarized')\n",
    "plt.plot(ms1, tv1, 'b', label='vectorized')\n",
    "plt.legend(loc='upper left')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "From the plot above, we see that the time needed for a fully vectorized model to compile is virtually constant, even as the number of constraints varies over an order of magnitude. The scalarized model is subtantially slower than the vectorized model (even when m=250), and it exhibits a clear linear trend in the runtime complexity.\n",
    "\n",
    "It might be tempting to think that a linear trend in the number of constraints isn't a problem, and in some cases, it really isn't! However when practitioners solve larger and larger optimization problems, the number of variables tends to vary with the number of constraints. This coupling effectively means that when an engineer \"linearly\" increases the resolution of their optimization problem, cvxpy is actually handled problems that grow quadratically, if not worse. \n",
    "\n",
    "# Test 2: Vary n with m.\n",
    "\n",
    "In the following test, we compare cvxpy compile times for vectorized and scalarized models when n varies with m. To keep the runtime of this test to a reasonable level, we fix n = 2 * m. Note that even with this choice, it takes a few minutes for the following cell to run on our machine."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x7f17b00c3910>"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD8CAYAAABn919SAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAIABJREFUeJzt3XucjeX+//HXxySD5JDDngjtdu1Sjg1JJB2QbKVU6KDdAV+pKO2ovR06t+nwo3Z9VSLZRTrZHWyHQg4VahSpLX2xNc7CSGRmrt8f12IGM+a01rrXWvN+Ph7rMWvuda9ZH/cs77nWdV/XdZtzDhERiX9lgi5ARETCQ4EuIpIgFOgiIglCgS4ikiAU6CIiCUKBLiKSIBToIiIJQoEuIpIgFOgiIgnimGi+WPXq1V39+vWj+ZIiInFv6dKlW51zNQraL6qBXr9+fZYsWRLNlxQRiXtmtrYw+6nLRUQkQSjQRUQShAJdRCRBRLUPPS/79+9n/fr17N27N+hSEk5ycjJ16tShbNmyQZciIlFQYKCbWTIwDygX2n+qc26YmY0H2gI7Q7ve5JxLK2oB69evp1KlStSvXx8zK+rTJR/OObZt28b69es5+eSTgy5HRKKgMC30fcCFzrndZlYWmG9mH4Ueu9c5N7UkBezdu1dhHgFmxgknnMCWLVuCLkVEoqTAQHf+kka7Q9+WDd3CepkjhXlk6LiKlC6FOilqZklmlgZsBmY65z4PPfSImX1tZk+bWbl8ntvbzJaY2RK1FkWk1NmxA+68E3btivhLFSrQnXNZzrkmQB2ghZmdBQwBTgeaA9WA+/J57ljnXKpzLrVGj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ZzzjmHOXPmsG3bNvbv38+bb74ZpqMgIkW2di20aePDfOBAf/IzoDCHWGuhB+Sbb77h3nvvpUyZMpQtW5bnn38e5xx33HEHv/76K+XLl2fWrFn069ePq666ijfffJN27drl2eIuzD6He/LJJ0lPT6dFCz9QqEuXLjz44IM8/PDDtG/fnuzsbMqWLctzzz1Hy5YtGT58OOeeey4pKSk0a9asUH80RCTMPvgAbrgBsrLgrbfgyiuDrgjzE0GjIzU11R1+EnHlypWcccYZUauhtNHxFQmzzEwYOhQeewwaN4apU+EPf4joS5rZUudcakH7qYUuIlJYGzdC9+6+a+XWW2H0aChfPuiqDlKgi4gUxty5Psx37oTx46FXr6ArOoJOioqIHE12tu9eufBCOP54+PzzmAxzUAtdRCR/27fDjTf6E6DXXAMvvQSVKgVdVb4U6CIieVm8GK6+GtLTYcwYuP12iPE5IOpyERHJzTl47jm//opzMH8+9O8f82EOCvSwePfdd/n222+L/LwXXniBV199tcSvX79+fbZu3VrinyNS6mVkQM+ePsAvuQS+/BJaxM9CsupyCYN3332Xzp0706BBg0I/JzMzk759S76emYiEyfLl0K0brFoFjz4K990HZeKrzVvqA/2+++6jXr169OvXD/BrqlSqVIns7GymTJnCvn376Nq1KyNGjADg1VdfZdSoUZgZjRo14n/+53+YNm0ac+fO5eGHH+att94iIyODvn37smfPHk455RTGjRtH1apVueCCC2jVqhULFiygS5cuZGRkcNxxx9GzZ086dep0sKZvvvmGH3/8kQoVKtC3b1/WrVsHwDPPPMN5553Htm3b6NGjB1u2bKFFixZEc3KYSEKaOBH69PGjWGbNgnbtgq6oWGIq0INYPbd79+4MGDDgYKBPmTKFwYMHM3/+fL744gucc3Tp0oV58+Zxwgkn8Mgjj7BgwQKqV6/O9u3bqVatGl26dKFz585069YNgEaNGjFmzBjatm3L0KFDGTFiBM+EitixYwdz584F/B8PgBNPPJG00D/8ueeeY+7cudSrV4+ePXsycOBAWrduzbp16+jQoQMrV65kxIgRtG7dmqFDh/LBBx8wduzY8B40kdJi715/ebg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X+UfQOv1/xlArsAb4Y2xfKxPZr86ouJus3sASATmBTatAGo65xrCtwN/NPMjifYeov6u4+FY9uDQxsjMXNc88itfHfNY1tYj2/MBLqZlcUflEnOubcBnHObnHNZzrls4EVyPvoX6gLVkeScSw993Qy8E6pt04GulNDXzaHdA68X/4fnS+fcJojtYxtS1GMZeN2hk1mdgetCH/cJdV9sC91fiu+LPi1Ub+5umajVW4zffaDH1syOAa4EJh/YFivHNa/cIsD3bkwEeqh/7GVgpXPuqVzbc/czdwUOnP2eBnQ3s3JmdjJwKv5ESLTqrWhmlQ7cx58QWx6q68AZ6l7Ae7nqvTF0lrslsPPAR7IoOqSFE6vHNpeiHst/A+3NrGqoC6F9aFtUmFlH4D6gi3NuT67tNcwsKXT/9/jj+WOo5gwzaxl6/9+Y698Y6VqL+rsP+oLwFwPfOecOdqXEwnHNL7cI8r0bibO/Rb0BrfEfMb4G0kK3TsBE4JvQ9mlASq7nPID/q/w9ETqLfZR6f48/078MWAE8ENp+AjAbWBX6Wi203YDnQvV+A6RGud4KwDagcq5tMXNs8X9oNgD78a2VW4pzLPF91z+Ebn+Ocr0/4PtBD7x/Xwjte1XoPbIM+BL4U66fk4oP09XAs4Qm+kWh1iL/7kP/H/8TeuyBaB3X0PbxQN/D9g30uIZeJ7/cCuy9q5miIiIJIia6XEREpOQU6CIiCUKBLiKSIBToIiIJQoEuIpIgFOgiIglCgS4ikiAU6CIiCeL/A2//yMIGq04cAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f17b608fc10>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ms2 = [250, 500, 1000, 1500, 2000]\n",
    "n_m_factor = 2\n",
    "ts2 = list()\n",
    "tv2 = list()\n",
    "for m in ms2:\n",
    "    A, b, c = gen_A_b_c(m, n=n_m_factor * m)\n",
    "    p = vectorized_problem(A, b, c)\n",
    "    tv2.append(compile_time(p, solver))\n",
    "    p = scalarized_problem(A, b, c)\n",
    "    ts2.append(compile_time(p, solver))\n",
    "    \n",
    "plt.plot(ms2, ts2, 'r', label='scalarized')\n",
    "plt.plot(ms2, tv2, 'b', label='vectorized')\n",
    "plt.legend(loc='upper left')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "From the plot above we see that even the fully vectorized model exhibits a super-linear time complexity as the number of constraints increases. However, the extent to which this happens is tolerable for a variety of applications. The situation is different with the scalarized model; that model takes almost a full minute to handle the case with m=2000 and n=4000!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Closing Remarks\n",
    "\n",
    "We'd like to emphasize that these test cases are quite tame. The usefulness of cvxpy arises not from providing an interface for linear programming, but from providing an interface for a broad range of tractable convex programs. The work performed by cvxpy is to allow the user to provide natural input using these constructions, then transform that input for low level solvers with very rigid input requirements. The more complex these transformations are, the more the user benefits from specifying vectorized models. \n",
    "\n",
    "In fact, this notebook was written after a user working with the exponential cone (via the function kl_div) found that a *more* vectorized version of their model compiled in less than one second, while a *less* vectorized version of the same model took over 20 minutes to compile."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    ""
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2.0
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
